package com.lie.prepare.multi_thread.queue;

/**
 * Created by lie on 2018/4/9.
 * 吃吐司的人~
 */
public class ToastConsumer implements Runnable{

    private int counter = 0;
    private ToastQueue finishedQueue;

    public ToastConsumer(ToastQueue finishedQueue) {
        this.finishedQueue = finishedQueue;
    }

    public void run() {
        try {
            while (! Thread.interrupted()){
                Toast t = finishedQueue.take();
                if (t.getId() != counter++ || t.getStatus() != Toast.Status.JAMMED) {
                    System.out.println("error");
                    System.exit(1);
                }else
                    System.out.println("撕咬 " + t+"\n\n");

            }
        }catch (InterruptedException e) {
            System.out.println("ToastConsumer InterruptedException");
        }

        System.out.println("吃不动了，打嗝儿\n\n");
    }
}
